<?php
//入库
namespace app\adminbackstage\model;

use think\Model;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Inventory extends Model{

    // 模型初始化
    protected static function init()
    {
        parent::init();
        //TODO:初始化内容
    }
    
    //入库列表
    public static function inventoryList($where,$page,$num){
        $list = self::field('i.*,p.p_name,p.p_num,w.w_name')
            ->alias('i')
            ->leftJoin('product p','p.id = i.p_id')
            ->leftJoin('warehouse w','w.id = i.w_id')
            ->where($where)
            ->limit(($page-1)*$num,$num)
            ->select();
        return $list;
    }
    
    //入库详情
    public static  function inventoryInfo($where){
        $info = self::where($where)
         ->find();
        return $info;
    }
    
    //入库数
    public static function inventoryCount($where) {
        return self::field('i.*,p.p_name,p.p_num,w.w_name')
            ->alias('i')
            ->leftJoin('product p','p.id = i.p_id')
            ->leftJoin('warehouse w','w.id = i.w_id')
            ->where($where)
            ->count();
    }

    //入库修改
    public static function inventoryEdit($id,$update){
        $in = self::update($update, ['id' => $id]);
        return $in;
    }
    

    //入库添加
    public static function inventoryAdd(array $data){
        return self::create($data);
    }
    
    
    public static function sumWareQuantity(){     
        $sum = self::where($where)
        ->sum('ware_quantity');
        return $sum;
    }
    
    public static function sumSold(){     
        $sum = self::where($where)
        ->sum('sold');
        return $sum;
    }
  
}
